// DisplayOptionPage.cpp : implementation file
//

#include "stdafx.h"
#include "kwclientcore.h"
#include "DisplayOptionPage.h"
#include "ClientConfiguration.h"
#include "MainPanel.h"

#include "GUIBaseLib\TopPropertySheet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDisplayOptionPage property page

IMPLEMENT_DYNCREATE(CDisplayOptionPage, CPropertyPage)

CDisplayOptionPage::CDisplayOptionPage() : CPropertyPage(CDisplayOptionPage::IDD)
{
	//{{AFX_DATA_INIT(CDisplayOptionPage)
	m_nArrangeStyle = -1;
	m_nSortBy = -1;
	//}}AFX_DATA_INIT
}

CDisplayOptionPage::~CDisplayOptionPage()
{
}

void CDisplayOptionPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDisplayOptionPage)
	DDX_Control(pDX, IDC_OODPPL, m_cbNumOfColumns);
	DDX_Radio(pDX, IDC_OOHV, m_nArrangeStyle);
	DDX_CBIndex(pDX, IDC_OPTIONDISPLAY_SORTBY, m_nSortBy);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDisplayOptionPage, CPropertyPage)
	//{{AFX_MSG_MAP(CDisplayOptionPage)
	ON_BN_CLICKED(IDC_OOHV, OnOohv)
	ON_CBN_SELCHANGE(IDC_OPTIONDISPLAY_SORTBY, OnSelchangeSortBy)
	ON_CBN_SELCHANGE(IDC_OODPPL, OnOohv)
	ON_BN_CLICKED(IDC_OOPNUM, OnOohv)
	ON_BN_CLICKED(IDC_OONAME, OnOohv)
	ON_BN_CLICKED(IDC_OOTYPE, OnOohv)
	ON_BN_CLICKED(IDC_OOTIME, OnOohv)
	ON_BN_CLICKED(IDC_OOVH, OnOohv)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDisplayOptionPage message handlers

BOOL CDisplayOptionPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
  ClientConfiguration * pClientConfiguration = ClientConfiguration::Instance();
  //m_nArrangeStyle = pClientConfiguration->m_Options.m_nArrangeStyle;
  for (int i = 0;i < 4;i++)
  {
    CheckDlgButton(IDC_OOPNUM+i,(pClientConfiguration->m_Options.m_dwDisplayContentMask>>i)&1);
  }

  CString str;
  str.Format("%d", pClientConfiguration->m_Options.m_nNumOfColumns);
  m_cbNumOfColumns.SelectString(-1, str);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CDisplayOptionPage::OnApply() 
{
	// TODO: Add your specialized code here and/or call the base class
  ClientConfiguration * pClientConfiguration = ClientConfiguration::Instance();
  pClientConfiguration->m_Options.m_nArrangeStyle = m_nArrangeStyle;
  
  int nIndex;
  CString str;
  nIndex = m_cbNumOfColumns.GetCurSel();
  m_cbNumOfColumns.GetLBText(nIndex, str);
  pClientConfiguration->m_Options.m_nNumOfColumns = atoi(str);
  pClientConfiguration->m_Options.m_dwDisplayContentMask = 0;
  for (int i = 0;i < 4;i++)
  {
    pClientConfiguration->m_Options.m_dwDisplayContentMask |= ((IsDlgButtonChecked(IDC_OOPNUM+i)!=0)<<i);
  }

  pClientConfiguration->m_Options.m_nSortBy = m_nSortBy+1;

	((CTopPropertySheet *)GetParent())->SetbModified();
  g_pMainPanel->ApplyOptions(OPM_DISPLAY);

	return CPropertyPage::OnApply();
}

void CDisplayOptionPage::OnOohv() 
{
	// TODO: Add your control notification handler code here
	SetModified(TRUE);
}

void CDisplayOptionPage::OnSelchangeSortBy() 
{
	// TODO: Add your control notification handler code here
	SetModified(TRUE);
}
